import 'package:flutter_admin/utils/utils.dart';

class StockPickingRequisition {
  String? id;
  String? locationId;
  String? locationName;
  String? productCode;
  String? productName;
  String? spec;
  String? qtyDone;
  String? productUomId;
  String? dateStart;
  String? dateEnd;

  StockPickingRequisition({
    this.id,
    this.locationId,
    this.locationName,
    this.productCode,
    this.productName,
    this.spec,
    this.qtyDone,
    this.productUomId,
    this.dateStart,
    this.dateEnd,
  });

  @override
  String toString() {
    return '''StockPickingRequisition{
      id: $id,
      locationId: $locationId,
      locationName: $locationName,
      productCode: $productCode,
      productName: $productName,
      spec: $spec,
      qtyDone: $qtyDone,
      productUomId: $productUomId,
    }''';
  }

  factory StockPickingRequisition.fromMap(Map<String, dynamic> map) {
    return new StockPickingRequisition(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      locationId: map['locationId'] != false
          ? map['locationId'].toString() as String?
          : "",
      locationName: map['locationName'] != false
          ? map['locationName'].toString() as String?
          : "",
      productCode: map['workshop_id'] != false
          ? map['workshop_id'][0].toString() as String?
          : "",
      productName: map['workshop_id'] != false
          ? map['workshop_id'][1].toString() as String?
          : "",
      spec: map['user_id'] != false
          ? map['user_id'][0].toString() as String?
          : "",
      qtyDone: map['user_id'] != false
          ? map['user_id'][1].toString() as String?
          : "",
      productUomId: map['write_date'] != false
          ? map['write_date'].toString() as String?
          : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'locationId': this.locationId,
      'locationName': this.locationName,
      'productCode': this.productCode,
      'productName': this.productName,
      'spec': this.spec,
      'qtyDone': this.qtyDone,
      'productUomId': this.productUomId,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    // ignore: unnecessary_cast
    List list = [
      if (this.productCode != null && this.productCode != '')
        ['workshop_id', '=', int.parse(this.productCode!)],
    ] as List;
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'locationId': this.locationId,
      'locationName': this.locationName,
      'workshop_id': int.parse(this.productCode!),
      'user_id': int.parse(this.spec!),
      'get_date': this.productUomId,
    } as Map<String, dynamic>;
  }
}
